package com.wzqj.agent.util;

import org.apache.commons.lang.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by wanghao@weipass.cn on 2015/7/31.
 */
public class ValidateUtil {

    /**
     * 校验是否是手机号
     * @param mobile
     * @return
     */
    public static boolean isMobile(String mobile){
        boolean flag = false;
        if(!StringUtils.isEmpty(mobile)){
            Pattern p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$"); // 验证手机号
            Matcher m = p.matcher(mobile);
            flag = m.matches();
        }
        return flag;
    }

    /**
     * 校验验证码格式
     * @return
     */
    public static boolean isCaptcha(String captcha){
        boolean flag = false;
        if(!StringUtils.isEmpty(captcha)){
            Pattern p = Pattern.compile("^[0-9]{4}$"); // 验证手机号
            Matcher m = p.matcher(captcha);
            flag = m.matches();
        }
        return flag;
    }

    /**
     * 校验图片url地址格式
     * @param iconUrl
     * @return
     */
    public static boolean isIconUrl(String iconUrl) {

        boolean flag = false;
        if(!StringUtils.isEmpty(iconUrl)){
            Pattern p = Pattern.compile("^http://(.*).(gif|jpg|jpeg|bmp|png)$"); // 验证手机号
            Matcher m = p.matcher(iconUrl);
            flag = m.matches();
        }
        return flag;
    }

    public void iisdadasd(String cardId,String card){
        String res = "";
        if(StringUtils.isEmpty(res)){
            System.out.println("res:"+res);
        }

    }

    /**
     * 校验设备类型
     * @param mt
     * @return
     */
    public static boolean isMt(String mt) {

        boolean flag = false;
        if(!StringUtils.isEmpty(mt)){
            if (mt.equals("android") || mt.equals("ios")){
                flag = true;
            }
        }
        return flag;
    }

    public static void main(String[] args) {

        System.out.printf(String.valueOf(isCaptcha("4324")));
        System.out.print(String.valueOf(isIconUrl("http://ddsad.ddasd.com/dsa/dsd.png")));
    }


}
